package com.tr.rentcar.controller.userc;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.bean.UserJf;
import com.tr.rentcar.model.dao.UserDao;
import com.tr.rentcar.model.dao.UserJfDao;

/**
 * Servlet implementation class UserJf
 */
@WebServlet("/user/jf")
public class UserJfsController extends HttpServlet {
	UserJfDao ujd=new UserJfDao();
	UserDao ud=new UserDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user=(User) request.getSession().getAttribute("userinfo");
		try {
			List<UserJf> uj=ujd.findByid(user.getUid(),0);
			User users = ud.findByid(user.getUid());
			request.setAttribute("ujf", users.getUjf());
			request.setAttribute("AllCount", ujd.getAllCount(user.getUid()));
			request.setAttribute("uj", uj);
			request.getRequestDispatcher("/WEB-INF/jsp/user_jf.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String Current=request.getParameter("Current");
		User user=(User) request.getSession().getAttribute("userinfo");
		int c=(Integer.parseInt(Current)-1)*13;
		PrintWriter out=response.getWriter();
		try {
			out.println(JSONArray.toJSONString(ujd.findByid(user.getUid(),c)));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
